define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		function get_data_distributor_credit(result) {
			if(false) {
				result = '{"success":true,"msg":"","result":{"store_id":"001","store_name":"世达","credit_line":10000,"credit":[{"info_id":"123456789","credit_line":1000,"new_debt":100,"repayment":900,"now_debt":200,"time":"2017/02/28","voucher":[{"id":"001","image":"img/bg-kef-img.png"},{"id":"002","image":"img/bg-kef-img.png"}]},{"info_id":"223456789","credit_line":1000,"new_debt":100,"repayment":900,"now_debt":200,"time":"2017/02/28","voucher":[{"id":"001","image":"img/bg-kef-img.png"},{"id":"002","image":"img/bg-kef-img.png"}]}],"now_debt":9999},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}

		function get_data_confrim_credit(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"store_id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}
		//返回信息
		return {
			distributor_credit: function(nPage,store_id, start_time, end_time, callback,calldone) {
				//								//post请求
				Http.post({
					method: 'member.agenter.credit.getlist',
					store_id: store_id,
					pagelimit: 15,
					nPage: nPage,
					start_time: start_time,
					end_time: end_time

				}, function(result) {
					if(callback)
						callback(get_data_distributor_credit(result).result);
				}, function(e) {

				}, function() {
					if(calldone)
					calldone();
				})
			},
			//确认还款
			confrim_credit: function(member_id, info_id, money, cancel, callback) {
				Http.post({
					method: 'member.agenter.credit.confirm',
					member_id:member_id,
					info_id: info_id,
					money: money,
					cancel:cancel
				}, function(result) {
					if(callback)
						callback(result)
				}, function(e) {

				}, function() {

				})
			}
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Distributor_creditrepayview", factory);
});